package com.example.helllo;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class SecondActivity extends AppCompatActivity {
    private  static final String TAG="ScoreActivity";
    int score=0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second2);
        TextView scorea=findViewById(R.id.scorea);
        TextView scoreb=findViewById(R.id.scoreb);
    }
    @Override
    public void onSaveInstanceState(@NonNull Bundle outState) {
        super.onSaveInstanceState(outState);
        String scorea=((TextView)findViewById(R.id.scorea)).getText().toString();
        String scoreb=((TextView)findViewById(R.id.scoreb)).getText().toString();
        Log.i(TAG, "onSaveInstanceState: ");
        outState.putString("teama_score",scorea);
        outState.putString("teamb_score",scoreb);
    }

    @Override
    protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        String scorea= savedInstanceState.getString("teama_score");
        String scoreb= savedInstanceState.getString("teamb_score");
        Log.i(TAG, "onRestoreInstanceState: ");
        ((TextView)findViewById(R.id.scorea)).setText(scorea);
        ((TextView)findViewById(R.id.scoreb)).setText(scoreb);
    }
    public void btn3a(View v){
        scorea(3);
    }
    public void btn2a(View v){
        scorea(2);
    }
    public void btn1a(View v){
        scorea(1);
    }
    public void btn3b(View v){
        scoreb(3);
    }
    public void btn2b(View v){
        scoreb(2);
    }
    public void btn1b(View v){
        scoreb(1);
    }
    public void btnReset(View v){
        TextView scorea=findViewById(R.id.scorea);
        TextView scoreb=findViewById(R.id.scoreb);
        scorea.setText("0");
        scoreb.setText("0");
    }
    private void scorea(int sc){
        TextView scorea=findViewById(R.id.scorea);
        String stra =scorea.getText().toString();
        int newsa= Integer.parseInt(stra)+sc;
        Log.i("score",":"+sc);
        scorea.setText(""+newsa);
    }
    private void scoreb(int sc){
        TextView scoreb=findViewById(R.id.scoreb);
        String strb =scoreb.getText().toString();
        int newsb= Integer.parseInt(strb)+sc;
        Log.i("score",":"+sc);
        scoreb.setText(""+newsb);
    }
    public void open(View v){
      Intent intent =new Intent(Intent.ACTION_DIAL, Uri.parse("tel:17844594990"));
      startActivity(intent);

    }


}